package com.liaogui.算法题;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author liaogui
 * @date 2025/3/27 23:03
 */
public class 小红书推荐系统 {
    public static void main(String[] args) {
        Map<String, Integer> treeMap = new TreeMap<>();
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String line = in.nextLine();
        line = line.trim();
        String[] lines = line.split(" ");
        Map<String, Integer> map = new HashMap<>();
        for(String nextLine: lines) {
            if(map.containsKey(nextLine)){
                int i = map.get(nextLine);
                map.put(nextLine, i+1);
            } else{
                map.put(nextLine, 1);
            }
        }
        // 按 value 排序
        List<Integer> collect = map.values().stream().sorted(Comparator.reverseOrder()).limit(3).collect(Collectors.toList());
        for (Integer integer : collect) {
            for (Map.Entry<String, Integer> entry : map.entrySet()) {
                if (Objects.equals(entry.getValue(), integer)) {
                    treeMap.put(entry.getKey(), integer);
                    map.remove(entry.getKey());
                    break;
                }
            }
        }
        System.out.println(treeMap.toString());
    }
}
